gravity:
    .byte $80,$00

ground: 
	.byte $00,$f2,$00

.var ADR = $40
do_dynamic:
	
	//change velocity 
	ldy #DYN_PUSHING
	lda (THIS),Y
	and #%00000001
	cmp #%00
	bne pushing_left_jmp
	lda (THIS),Y
	and #%00000010
	cmp #%00
	bne pushing_right_jmp
	jmp nopushing
pushing_left_jmp:
	jmp pushing_left
pushing_right_jmp:
	jmp pushing_right
pushing_left:
	:copyFromThisOff(DYN_XVELO,NUM1,2)
	:copyFromThisOff(DYN_MIN_XVELO,NUM2,2)
	:branchIfNotEqual(NUM1,NUM2,2,left_accelerate)
	jmp pushing_end
left_accelerate:
	:copyFromThisOff(DYN_RUN_ACCEL,NUM2,2)
	:copyFromThisOff(DYN_XVELO,NUM1,2)
	:Sub(NUM1,NUM2,NUM3,2)
	:copyFromThisOff(DYN_MIN_XVELO,NUM2,2)
	:branchIfLesser(NUM3,NUM2,2,lmax_velo)
	jmp lmax_velo_end
lmax_velo:
	:copy(NUM2,NUM3,2)
lmax_velo_end:
	:copyToThisOff(DYN_XVELO,NUM3,2)
	jmp pushing_end
pushing_right:
	:copyFromThisOff(DYN_XVELO,NUM1,2)
	:copyFromThisOff(DYN_MAX_XVELO,NUM2,2)
	:branchIfNotEqual(NUM1,NUM2,2,right_accelerate)
	jmp pushing_end
right_accelerate:
	:copyFromThisOff(DYN_RUN_ACCEL,NUM2,2)
	:copyFromThisOff(DYN_XVELO,NUM1,2)
	:Add(NUM1,NUM2,NUM3,2)
	:copyFromThisOff(DYN_MAX_XVELO,NUM2,2)
	:branchIfLesser(NUM2,NUM3,2,rmax_velo)
	jmp rmax_velo_end
rmax_velo:
	:copy(NUM2,NUM3,2)
rmax_velo_end:
	:copyToThisOff(DYN_XVELO,NUM3,2)
	jmp pushing_end
nopushing:
	:setZero(NUM1,2)
	:copyToThisOff(DYN_XVELO,NUM1,2)
pushing_end:

	//test jump
	ldy #DYN_PUSHING
	lda (THIS),Y
	and #%00000100
	cmp #00
	bne pushing_jump
	jmp do_jump_end
pushing_jump:
	lda (THIS),Y
	and #%11111011
	sta (THIS),Y
	:copyFromThisOff(DYN_AREIAL,NUM1,1)
	lda #$00
	cmp NUM1
	beq do_jump
	jmp do_jump_end
do_jump:
	inc NUM1
	:copyToThisOff(DYN_AREIAL,NUM1,1)
	inc $0408
	:copyToThis(NUM1,1)
	:copyFromThisOff(DYN_JUMP_VELO,NUM1,2)
	:copyToThisOff(DYN_YVELO,NUM1,2)
do_jump_end:

	:copyFromThisOff(DYN_AREIAL,NUM1,1)
	lda #$01
	cmp NUM1
	beq aerial
	jmp aerial_end
aerial:
	:copyFromThisOff(DYN_YVELO,NUM1,2)
	:UpscaleSignedNum(NUM1,2,3) //NUM1 Xvelo
	:copyFromThisOff(DYN_YPOS,NUM2,3) //num2 xpos
	:Add(NUM1,NUM2,NUM3,3)
	
	:branchIfLesser(ground,NUM3,3,hit_the_ground)
	jmp hit_the_ground_end
hit_the_ground:
	:copyToThisOff(DYN_YPOS,ground,3)
	:setZero(NUM3,2)
	:copyToThisOff(DYN_YVELO,NUM3,2)
	:copyToThisOff(DYN_AREIAL,NUM3,1)
	jmp aerial_end
hit_the_ground_end:
	:copyToThisOff(DYN_YPOS,NUM3,3)
	//gravity to y
	:copy(gravity,NUM2,2)
	:Add(NUM1,NUM2,NUM3,2)
	:copyToThisOff(DYN_YVELO,NUM3,2)
	
aerial_end:

//add velo to position
	:copyFromThisOff(DYN_XVELO,NUM1,2)
	:UpscaleSignedNum(NUM1,2,3) //NUM1 Xvelo
	:copyFromThisOff(DYN_XPOS,NUM2,3) //num2 xpos
	:Add(NUM1,NUM2,NUM3,3)
	:copyToThisOff(DYN_XPOS,NUM3,3)
do_dynamic_end:
    rts
	
show_fighter:

	:copyFromThisOff(DYN_XPOS+1,NUM1,2) //NUM1 = posX
	:copyFromThisOff(DYN_YPOS+1,NUM2,1) //NUM2 = posY
	
	ldy #DYN_AREIAL
	lda (THIS),Y
	cmp #$01
	beq jumping
	jmp jumping_end
jumping:
	ldy #DYN_ORIENTATION
	lda (THIS),Y
	cmp #$00
	beq jumping_left
	jmp jumping_right
jumping_left:
	ldy #DYN_LJUMP
	jmp jumping_right_end
jumping_right:
	ldy #DYN_RJUMP
jumping_right_end:
	:copyFromThis(ADR,2)
	:showSpriteA(ADR,NUM1,NUM2)
	jmp show_fighter_end
jumping_end:

.print "jumping=$"+toHexString(jumping)
	
	:copyFromThisOff(DYN_XVELO,NUM3,2)
	:branchIfNotZero(NUM3,2,moving)
	jmp standing
moving:
	ldy #DYN_ORIENTATION
	lda (THIS),Y
	cmp #$00
	beq running_left
	jmp running_right
running_left:
	ldy #DYN_LRUN
	jmp running_right_end
running_right:
	ldy #DYN_RRUN
running_right_end:
	:copyFromThis(ADR,2)
	:playAnimationA(ADR,NUM1,NUM2)
	jmp show_fighter_end
	
standing:
	ldy #DYN_ORIENTATION
	lda (THIS),Y
	cmp #$00
	beq left_standing
	jmp right_standing
left_standing:
	ldy #DYN_LSTAND
	jmp right_standing_end
right_standing:
	ldy #DYN_RSTAND
right_standing_end:
	:copyFromThis(ADR,2)
	:showSpriteA(ADR,NUM1,NUM2)
show_fighter_end:
	rts
	